<?php
header ( "Content-Type: text/html; charset=utf-8" );
session_name("mulibabook");
session_start();

$_SESSION['n1'] = rand(1,20);
$_SESSION['n2'] = rand(1,20);
$_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2'];

require_once ("config.inc.php");
require_once (COMM_PATH . "book.php");
require_once(COMM_PATH . "bookUtil.php");
$book = new Book ();
$CP = "联系我们";

?>
<?php
include_once 'top.php';
?>

<div class="b_lofter bgWhite">
<div class="breadcrumb">
	您的位置：<a href="/" title="木篱笆书站">首页</a>&nbsp;/&nbsp;<?php echo $CP; ?>
</div>
<div class="brline">
</div>
<div class="book_list">
<div class="contact">
<p>木篱笆书站是完全免费的网上图书阅读站点，这里的图书全部来源于网络。<br />
书籍文化有时代、地域等特性立场，本站所有收藏的图书和文章留言内容广泛，都是代表作者以及读友本身的意见，不代表本站立场。<br />
各位读友对本站有任何意见或者建议请在此留言，或者发现书籍内容有误的也请在此指出，请注明书籍名称、错误的词汇、正确的词汇，如（心倩/心情）,谢谢
</p>
<form action="" name="contactForm" id="contactForm" method="post" >
<p><input type="text" name="author" id="author" value="" size="22"
	tabindex="1"> <label for="author">姓名*</label><label id="autor_err" style="padding-left:10px;color:red;"></label>
</p>
<p><input type="text" name="email" id="email" value="" size="22"
	tabindex="1"> <label for="email">Email*</label><label id="email_err" style="padding-left:10px;color:red;"></label>
</p>
<p><input type="text" name="captcha" id="captcha" value="" size="22"
	tabindex="1"><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> = ?</label>
	<label id="captcha_err" style="padding-left:10px;color:red;"></label></p>
<p><textarea name="comment" id="comment" cols="60" rows="8"
	tabindex="4"></textarea></p>
<p>
	<a href="#" rel="home" title="提交"  id="contactSubmit"><span>提交</span></a>
</p>
</form>
</div>
</div>
</div>


<?php
include_once 'footer.php';
?>

<script type="text/javascript">
var hexToDec = function(str) {
	str=str.replace(/\\/g,"%");
	return unescape(str);
};
	$(function(){
		$("#contactSubmit").click(function(){
			if(checkForm()){
				var email_val = $("#email").val();
		        var author_val = $("#author").val();
		        var comment_val = $("#comment").val();
		       	var data = {author:author_val,email:email_val,comment:comment_val};
				 $.ajax({
					url: 'conSubmit.php',
				    type: 'POST',
				    data: data,
				    error: function(){
				     	alert('Error loading XML document');
				    },
				    success: function(html){
				     	alert(hexToDec(eval(html)));
				     	location.reload();
				    }
				 });
			}
		});
	});
	function checkForm(){
		$("#autor_err").html("");
		$("#email_err").html("");
		$("#captcha_err").html("");
		var cap = <?php echo $_SESSION['expect'];?>;
	    var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
        var email_val = $("#email").val();
        var author_val = $("#author").val();
        var captcha_val = $("#captcha").val();
        if(author_val==""){
			$("#autor_err").html("姓名不能为空");
			return false;
        }
        if(email_val==""){
			$("#email_err").html("Email不能为空");
			return false;
        }
        if(search_str.test(email_val)){
        }else{
    	   $("#email_err").html("Email格式不正确");
			return false;
        }
        if(captcha_val==""){
			$("#captcha_err").html("验证码不能为空");
			return false;
    	}
        if(captcha_val!=cap){
			$("#captcha_err").html("验证码不正确");
			return false;
  	    }
        

         return true;
	}

</script>
